﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq.Expressions;
using System.Threading.Tasks;

namespace WxTenpay.Service
{
    public interface IBaseService<T> where T : class
    {
        #region  异步数据

        #region 添加操作
        /// <summary>
        /// 添加一条数据
        /// </summary>
        /// <param name="parm">cms_advlist</param>
        /// <returns></returns>
        Task<ApiResult<string>> AddAsync(T parm, bool Async = true);

        /// <summary>
        /// 批量添加数据
        /// </summary>
        /// <param name="parm">List<T></param>
        /// <returns></returns>
        Task<ApiResult<string>> AddListAsync(List<T> parm, bool Async = true);

        #endregion

        #region 查询操作
        /// <summary>
        /// 获得列表
        /// </summary>
        /// <param name="where">Expression<Func<T, bool>></param>
        /// <param name="order">Expression<Func<T, object>></param>
        /// <param name="orderEnum">DbOrderEnum</param>
        /// <returns></returns>
        Task<ApiResult<List<T>>> GetListAsync(Expression<Func<T, bool>> where,
            Expression<Func<T, object>> order, bool Async = true);

        /// <summary>
        /// 获得列表
        /// </summary>
        /// <returns></returns>
        Task<ApiResult<List<T>>> GetListAsync(bool Async = true);

        /// <summary>
		/// 获得列表——分页
		/// </summary>
		/// <param name="parm">PageParm</param>
		/// <returns></returns>
		Task<ApiResult<PageModel.Page<T>>> GetPagesAsync(PageModel.PageParm parm, bool Async = true);

        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="parm">分页参数</param>
        /// <param name="where">条件</param>
        /// <param name="order">排序值</param>
        /// <param name="orderEnum">排序方式OrderByType</param>
        /// <returns></returns>
        Task<ApiResult<PageModel.Page<T>>> GetPagesAsync(PageModel.PageParm parm, Expression<Func<T, bool>> where,
            Expression<Func<T, object>> order, int OrderBy, bool Async = true);

        /// <summary>
        /// 获得一条数据
        /// </summary>
        /// <param name="parm">string</param>
        /// <returns></returns>
        Task<ApiResult<T>> GetModelAsync(string parm, bool Async = true);

        /// <summary>
        /// 获得一条数据
        /// </summary>
        /// <param name="where">Expression<Func<T, bool>></param>
        /// <returns></returns>
        Task<ApiResult<T>> GetModelAsync(Expression<Func<T, bool>> where, bool Async = true);
        #endregion

        #region 修改操作
        /// <summary>
        /// 修改一条数据
        /// </summary>
        /// <param name="parm">T</param>
        /// <returns></returns>
        Task<ApiResult<string>> UpdateAsync(T parm, bool Async = true);

        /// <summary>
        /// 修改一条数据
        /// </summary>
        /// <param name="parm">T</param>
        /// <returns></returns>
        Task<ApiResult<string>> UpdateAsync(List<T> parm, bool Async = true);

        /// <summary>
        /// 修改一条数据，可用作假删除
        /// </summary>
        /// <param name="columns">修改的列=Expression<Func<T,T>></param>
        /// <param name="where">Expression<Func<T,bool>></param>
        /// <returns></returns>
        Task<ApiResult<string>> UpdateAsync(Expression<Func<T, T>> columns,
            Expression<Func<T, bool>> where, bool Async = true);
        #endregion

        #region 删除操作
        /// <summary>
        /// 删除一条或多条数据
        /// </summary>
        /// <param name="parm">string</param>
        /// <returns></returns>
        Task<ApiResult<string>> DeleteAsync(string parm, bool Async = true);

        /// <summary>
        /// 删除一条或多条数据
        /// </summary>
        /// <param name="where">Expression<Func<T, bool>></param>
        /// <returns></returns>
        Task<ApiResult<string>> DeleteAsync(Expression<Func<T, bool>> where, bool Async = true);

        #endregion

        #region 查询Count
        Task<ApiResult<int>> CountAsync(Expression<Func<T, bool>> where, bool Async = true);
        #endregion

        #region 是否存在
        Task<ApiResult<bool>> IsExistAsync(Expression<Func<T, bool>> where, bool Async = true);
        #endregion
        #endregion

        #region 同步数据
        #region 添加操作
        /// <summary>
        /// 添加一条数据
        /// </summary>
        /// <param name="parm">cms_advlist</param>
        /// <returns></returns>
        int Add(T parm);

        /// <summary>
        /// 批量添加数据
        /// </summary>
        /// <param name="parm">List<T></param>
        /// <returns></returns>
        int AddList(List<T> parm);

        #endregion

        #region 查询操作
        /// <summary>
        /// 获得列表
        /// </summary>
        /// <param name="where">Expression<Func<T, bool>></param>
        /// <param name="order">Expression<Func<T, object>></param>
        /// <param name="orderEnum">DbOrderEnum</param>
        /// <returns></returns>
        List<T> GetList(Expression<Func<T, bool>> where,
            Expression<Func<T, object>> order);

        /// <summary>
        /// 获得列表
        /// </summary>
        /// <param name="where">Expression<Func<T, bool>>条件</param>
        /// <returns></returns>
        List<T> GetList(Expression<Func<T, bool>> where);
        /// <summary>
        /// 获得列表
        /// </summary>
        /// <returns></returns>
        List<T>  GetList();

        /// <summary>
		/// 获得列表——分页
		/// </summary>
		/// <param name="parm">PageParm</param>
		/// <returns></returns>
		PageModel.Page<T> GetPages(PageModel.PageParm parm);



        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="parm">分页参数</param>
        /// <param name="order">排序值</param>
        /// <param name="orderEnum">排序方式OrderByType</param>
        /// <returns></returns>
        PageModel.Page<T> GetPages(PageModel.PageParm parm,
            Expression<Func<T, object>> order, int OrderBy);


        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="parm">分页参数</param>
        /// <param name="where">条件</param>
        /// <param name="order">排序值</param>
        /// <param name="orderEnum">排序方式OrderByType</param>
        /// <returns></returns>
        PageModel.Page<T> GetPages(PageModel.PageParm parm, Expression<Func<T, bool>> where,
            Expression<Func<T, object>> order, int OrderBy);

        /// <summary>
        /// 获得一条数据
        /// </summary>
        /// <param name="parm">string</param>
        /// <returns></returns>
        T GetModel(string parm);

        /// <summary>
        /// 获得一条数据
        /// </summary>
        /// <param name="where">Expression<Func<T, bool>></param>
        /// <returns></returns>
        T GetModel(Expression<Func<T, bool>> where);
        #endregion

        #region 修改操作
        /// <summary>
        /// 修改一条数据
        /// </summary>
        /// <param name="parm">T</param>
        /// <returns></returns>
        int Update(T parm);

        /// <summary>
        /// 修改一条数据
        /// </summary>
        /// <param name="parm">T</param>
        /// <returns></returns>
        int Update(List<T> parm);

        /// <summary>
        /// 修改一条数据，可用作假删除
        /// </summary>
        /// <param name="columns">修改的列=Expression<Func<T,T>></param>
        /// <param name="where">Expression<Func<T,bool>></param>
        /// <returns></returns>
        int Update(Expression<Func<T, T>> columns,
            Expression<Func<T, bool>> where);
        #endregion

        #region 删除操作
        /// <summary>
        /// 删除一条或多条数据
        /// </summary>
        /// <param name="parm">string</param>
        /// <returns></returns>
        int Delete(string parm);

        /// <summary>
        /// 删除一条或多条数据
        /// </summary>
        /// <param name="where">Expression<Func<T, bool>></param>
        /// <returns></returns>
        int Delete(Expression<Func<T, bool>> where);

        #endregion

        #region 查询Count
        int Count(Expression<Func<T, bool>> where);
        #endregion

        #region 是否存在
        bool IsExist(Expression<Func<T, bool>> where);
        #endregion
        #endregion

        #region 执行sql
        /// <summary>
        /// 新增 或者修改
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="pams"></param>
        /// <returns></returns>
        int insertsql(string sql, object pams);


        /// <summary>
        /// 执行查询sql 
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="pams"></param>
        /// <returns></returns>
        List<T> SelectSql(string sql, object pams);



        /// <summary>
        /// 执行查询sql to datatable
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="pams"></param>
        /// <returns></returns>
        DataTable DataSql(string sql, object pams);

        #endregion

    }
}
